package com.hemaapp.yjnh.adapter;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.uu.utils.uuUtils;
import com.hemaapp.hm_FrameWork.HemaAdapter;
import com.hemaapp.yjnh.R;
import com.hemaapp.yjnh.bean.Cash;

/**
 * 提现记录
 */
public class CashAdapter extends HemaAdapter {

	private ArrayList<Cash> cashs;

	public CashAdapter(Context mContext, ArrayList<Cash> cashs) {
		super(mContext);
		this.cashs = cashs;
	}

	@Override
	public int getCount() {
		int size = cashs == null ? 0 : cashs.size();
		return size == 0 ? 1 : cashs.size();
	}

	@Override
	public boolean isEmpty() {
		int size = cashs == null ? 0 : cashs.size();
		return size == 0;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (isEmpty())
			return getEmptyView(parent);
		ViewHolder holder;
		if (convertView == null || convertView.getTag(R.id.TAG_VIEWHOLDER) == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_cash_record, null);
			holder = new ViewHolder(convertView);
			convertView.setTag(R.id.TAG_VIEWHOLDER, holder);
		} else {
			holder = (ViewHolder) convertView.getTag(R.id.TAG_VIEWHOLDER);
		}
		holder.setDatas(position);
		return convertView;
	}

	class ViewHolder {
		@Bind(R.id.iv_way)
		ImageView ivWay;
		@Bind(R.id.tv_name)
		TextView tvName;
		@Bind(R.id.tv_date)
		TextView tvDate;
		@Bind(R.id.tv_total_fee)
		TextView tvTotalFee;

		ViewHolder(View view) {
			ButterKnife.bind(this, view);
		}

		public void setDatas(int position) {
			Cash cash = cashs.get(position);
			String keytype = cash.getKeytype();
			if ("2".equals(keytype)) {// 支付宝
				ivWay.setImageResource(R.drawable.img_paytyp_alipay);
				tvName.setText("支付宝充值");
			} else if ("1".equals(keytype)) {// 银联
				ivWay.setImageResource(R.drawable.img_paytyp_union);
				tvName.setText("银联充值");
			}
			tvDate.setText(cash.getRegdate());
			tvTotalFee.setText("-"+uuUtils.formatAfterDot2(cash.getApplyfee()));
		}
	}

}
